package com.sinopec.android.adapter;

import java.util.ArrayList;


import com.sinopec.android.R;
import com.sinopec.android.bean.Conference;
import com.sinopec.android.bean.Thing;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
* @ClassName: ConferenceListAdapter
* @Description: TODO(会议管理适配器)
* @author liuwei
* @date 2012-3-28 下午04:07:10
* 
*/
public class ConferenceListAdapter extends BaseAdapter {
	public ArrayList<Conference> listData;
	private Conference conference;
	private Context context;
	private LayoutInflater inflater ;
	
	public ConferenceListAdapter(Context context,ArrayList<Conference> listData){
		this.context = context;
		inflater = LayoutInflater.from(context);
		this.listData = listData;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(listData!=null){
			return listData.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
		if(convertView ==null){
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.conference_item, null);
			viewHolder.title = (TextView) convertView.findViewById(R.id.conference_title_textview);
			viewHolder.time = (TextView) convertView.findViewById(R.id.conference_time_textview);
			viewHolder.address = (TextView) convertView.findViewById(R.id.conference_address_textview);
			viewHolder.flag = (ImageView) convertView.findViewById(R.id.conference_flag);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if(position % 2 ==0){
			convertView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.odd_item_selector));
		}else{
			convertView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.even_item_selector));
		}
		if(listData!=null){
			conference = listData.get(position);
			viewHolder.title.setText(conference.getTitle());
			try{
				String[] time = conference.getTime().split(" ");
				
				viewHolder.time.setText(time[0]+" "+time[1]+" "+time[2]+"至"+time[3]);
				
			}catch (Exception e) {
				viewHolder.time.setText( conference.getTime());
			}
			viewHolder.address.setText(conference.getAddress());
		}
		
		return convertView ;
	}
	
	class ViewHolder{
		TextView title,time,address;
		ImageView flag;
		
	}

}
